package com.example.recuitactivity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.example.recuitactivity.R;
import com.example.recuitactivity.ViewRecruitInfoActivity;
import com.example.recuitactivity.bean.Deliver;

import java.util.List;

public class CandidateDeliveredAdapter extends RecyclerView.Adapter<CandidateDeliveredAdapter.DeliveredInfoViewHolder>{
    private List<Deliver> mDatas;
    private Context context;
    private String username;

    public CandidateDeliveredAdapter(){}
    public CandidateDeliveredAdapter(Context context, List<Deliver> mDatas,String username) {
        this.context = context;
        this.mDatas = mDatas;
        this.username=username;
    }

    public void setmDatas(List<Deliver> mDatas){
        this.mDatas=mDatas;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public DeliveredInfoViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rv_delivered_row_item, parent, false);
        DeliveredInfoViewHolder holder = new DeliveredInfoViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull DeliveredInfoViewHolder holder, int position) {
        Deliver bean = mDatas.get(position);
        holder.tv_name.setText(bean.getPostName());
        holder.tv_state.setText(bean.getState());
        holder.tv_time.setText(bean.getPostTime());
        holder.tv_search_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(context, ViewRecruitInfoActivity.class);
                intent.setAction("just_view");
                Bundle bundle=new Bundle();
                bundle.putString("username",username);
                bundle.putLong("cid",bean.getCid());
                bundle.putLong("eid",bean.getEid());
                bundle.putLong("pid",bean.getPid());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    class DeliveredInfoViewHolder extends RecyclerView.ViewHolder {
        TextView tv_name,tv_time,tv_state,tv_search_detail;
        public DeliveredInfoViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_name=(TextView) itemView.findViewById(R.id.tv_delivered_recruit_name);
            tv_time=(TextView) itemView.findViewById(R.id.tv_delivered_time);
            tv_state=(TextView) itemView.findViewById(R.id.tv_delivered_state);
            tv_search_detail=(TextView) itemView.findViewById(R.id.tv_delivered_search_detail);
        }
    }

}
